<?php
//返利
namespace app\adminbackstage\model;

use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Rebate extends Model{

    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }
    
    //返利列表
    public static function rebateList($where,$page,$num){
        $list = self::field('r.*,so.p_name')
        ->alias('r')
        ->leftJoin('sample_order  so','so.id = r.so_id')
        ->leftJoin('user u','u.uid = r.u_id')
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
    }
    
    //返利详情
    public static  function rebateInfo($where){
        $info = self::field('r.*,so.p_name,u.username')->alias('r')
        ->leftJoin('sample_order  so','so.id = r.so_id')
        ->leftJoin('user u','u.uid = r.u_id')
        ->where($where)
        ->find();
        return $info;
    }
    
    //返利数
    public static function rebateCount($where) {
        return self::field('r.*,so.p_name,u.username')->alias('r')
        ->leftJoin('sample_order  so','so.id = r.so_id')
        ->leftJoin('user u','u.uid = r.u_id')
        ->where($where)
        ->count();
    }

    //返利修改
    public static function rebateEdit($id,$update){
        $in = self::update($update, ['id' => $id]);
        return $in;
    }
    

    //返利添加
    public static function rebateAdd(array $data){
        return self::create($data);
    }
  
}
